package pho.prowon.category;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author Peter
 *
 * An object of this class is the definition of a categorization of Images
 * for the Tree Viewer. It has a list of tags after which images will be
 * categorized subsequently and a name for display.
 * The available IndexCategoryDefinitions are retrieved from XML files by the
 * IndexCategoryDefinitionFactory.
 * 
 * The following Meta-Tags are available (besides the XML names of the IPTC tags):
 * $$PATH$$ will categorize by the single parts (folders) of the pathName
 * $$YEAR$$ takes the year of the creation date
 * $$MONTH$$ takes the month of the creation date
 * $$DAY$$ takes the day of the creation date
 */
public class IndexCategoryDefinition implements Comparable
{

	// Properties
	private ArrayList categoryNames = new ArrayList();
	private String name;
	private String nameProperty;
	
	/**
	 * create an index category definition for a single category tag
	 * this is package private because the categories should only be created
	 * through the Factory
	 * @param cat the name of the tag to be categorized 
	 * @param defnam the name of the definition
	 * @param property the language property its name is based on (this is information only and will not be used in operation)
	 */
	IndexCategoryDefinition(String cat, String defname, String property)
	{
		super();
		categoryNames.add(cat);
		name = defname;
		nameProperty = property;
	}

	/**
	 * create an index category definition for a list of category tags
	 * this is package private because the categories should only be created
	 * through the Factory
	 * @param cats the List containing the category tags (Strings)
	 * @param defnam the name of the definition
	 * @param property the language property its name is based on (this is information only and will not be used in operation)
	 */
	IndexCategoryDefinition(List cats, String defname, String property)
	{
		super();
		categoryNames.addAll(cats);
		name = defname;
		nameProperty = property;
	}

	/**
	 * Get the Names of the Tags for categorization (Strings)
	 * @return	a List of categoy tag Names (strings)
	 */
	List getCategoryNames()
	{
		return (List) categoryNames.clone();
	}
	/**
	 * Get the name of the category defined
	 * @return the name of the category
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Get the name of the Language Property associated with the Category Name
	 * @return language property name
	 */
	public String getNameProperty()
	{
		return nameProperty;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString ()
	{
		String ret = getName() + "(";
		Iterator it = categoryNames.iterator();
		while (it.hasNext())
		{
			ret = ret + (String) it.next();
			if (it.hasNext())
			{
				ret = ret + "/";
			}
		}
		ret = ret + ")";
		return ret;
	}

	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	public int compareTo(Object o)
	{
		return getName().compareTo(getName());
	}
}
